package com.lanyan.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;
        import com.lanyan.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.lanyan.common.utils.StringUtils;
import com.lanyan.system.mapper.IndexImgMapper;
import com.lanyan.system.domain.IndexImg;
import com.lanyan.system.domain.vo.IndexImgVo;
import com.lanyan.system.service.IIndexImgService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 轮播图标Service业务层处理
 *
 * @author lanyan
 * @date 2024-11-26
 */
@Service
public class IndexImgServiceImpl  extends ServiceImpl<IndexImgMapper,IndexImg> implements IIndexImgService

{
    @Autowired
    private IndexImgMapper indexImgMapper;

    /**
     * 查询轮播图标
     *
     * @param indexImgId 轮播图标主键
     * @return 轮播图标
     */
    @Override
    public IndexImg selectIndexImgByIndexImgId(Long indexImgId)
    {
        return this.getById(indexImgId);
    }

    /**
     * 查询轮播图标Vo列表
     *
     * @param indexImg 轮播图标
     * @return 轮播图标
     */
    @Override
    public List<IndexImgVo> selectIndexImgVoList(IndexImg indexImg)
    {
        return selectIndexImgList(indexImg)
                .stream()
                .map(x -> (IndexImgVo)x)
                .collect(Collectors.toList());
    }
    /**
     * 查询轮播图标列表
     *
     * @param indexImg 轮播图标
     * @return 轮播图标
     */
    @Override
    public List<IndexImg> selectIndexImgList(IndexImg indexImg)
    {
        LambdaQueryChainWrapper<IndexImg> wrapper = this.lambdaQuery().eq(IndexImg::getDelFlag,"0");
        if (StringUtils.isNotEmpty(indexImg.getImgUrl())) {
            wrapper.eq(IndexImg::getImgUrl, indexImg.getImgUrl());
        }
        if (StringUtils.isNotEmpty(indexImg.getSort())) {
            wrapper.eq(IndexImg::getSort, indexImg.getSort());
        }
        return wrapper.list();
    }

        /**
         * 新增轮播图标
         *
         * @param indexImg 轮播图标
         * @return 结果
         */
    @Override
        public boolean insertIndexImg(IndexImg indexImg)
        {
                    indexImg.setCreateTime(DateUtils.getNowDate());
                return this.save(indexImg);
        }

        /**
         * 修改轮播图标
         *
         * @param indexImg 轮播图标
         * @return 结果
         */
    @Override
        public boolean updateIndexImg(IndexImg indexImg)
        {
                    indexImg.setUpdateTime(DateUtils.getNowDate());
            return this.updateById(indexImg);
        }

        /**
         * 批量删除轮播图标
         *
         * @param indexImgIds 需要删除的轮播图标主键
         * @return 结果
         */
    @Override
        public boolean deleteIndexImgByIndexImgIds(Long[] indexImgIds)
        {
            return this.lambdaUpdate().set(IndexImg::getDelFlag,"1").in(IndexImg::getIndexImgId,indexImgIds).update();
        }

        /**
         * 删除轮播图标信息
         *
         * @param indexImgId 轮播图标主键
         * @return 结果
         */
    @Override
        public boolean deleteIndexImgByIndexImgId(Long indexImgId)
        {
            return this.lambdaUpdate().set(IndexImg::getDelFlag,"1").eq(IndexImg::getIndexImgId,indexImgId).update();
        }
    }
